package com.canbot.u05.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.canbot.u05.R;
import com.canbot.u05.receivers.IntentKey;

/**
 * 感应器定制
 *
 * @author qiandu
 */
public class TouchSensorVoiceActivity extends BaseActivityNoTitle
        implements OnClickListener {

        private View prompt;

        private Button btnBack;

        private CheckBox cbSwitch;

        private RelativeLayout rlDisable;

        private RelativeLayout rlSensor;

        private ImageView ivHead;

        private ImageView ivLeftEar;

        private ImageView ivRightEar;

        private ImageView ivNeck;

        private ImageView ivLeftHand;

        private ImageView ivRightHand;

        private ImageView ivBelly;

        private ImageView ivHeadBack;

        private ImageView ivButt;

        private Button btn_head_back;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_sensor_back);
                initView();
        }

        private void initView() {
                prompt = (View) findViewById(R.id.prompt);
//                cbSwitch = (CheckBox) findViewById(R.id.cbSwitch);
                rlDisable = (RelativeLayout) findViewById(R.id.rlDisable);
                rlSensor = (RelativeLayout) findViewById(R.id.rlSensor);
                btn_head_back = (Button) findViewById(R.id.btn_head_back);
                btn_head_back.setOnClickListener(this);
                ivHead = (ImageView) findViewById(R.id.ivHead);// 头部感应器
                ivHead.setOnClickListener(this);
                ivLeftEar = (ImageView) findViewById(R.id.ivLeftEar);//
                ivLeftEar.setOnClickListener(this);
                ivRightEar = (ImageView) findViewById(R.id.ivRightEar);
                ivRightEar.setOnClickListener(this);
                ivNeck = (ImageView) findViewById(R.id.ivNeck);
                ivNeck.setOnClickListener(this);
//                ivLeftHand = (ImageView) findViewById(R.id.ivLeftHand);
//                ivLeftHand.setOnClickListener(this);
//                ivRightHand = (ImageView) findViewById(R.id.ivRightHand);
//                ivRightHand.setOnClickListener(this);
                ivBelly = (ImageView) findViewById(R.id.ivBelly);// 肚子感应器
                ivBelly.setOnClickListener(this);
//                ivHeadBack = (ImageView) findViewById(R.id.ivHeadBack);
//                ivHeadBack.setOnClickListener(this);
                ivButt = (ImageView) findViewById(R.id.ivButt);
                ivButt.setOnClickListener(this);

                prompt.setOnClickListener(this);
                // 提示界面只播放一次
                SharedPreferences sp = getSharedPreferences("sensor_prompt",
                        Context.MODE_PRIVATE);
                String isPlayed = sp.getString("isPlayed", "");
                if (null != isPlayed && !"".equals(isPlayed)
                        && "yes".equals(isPlayed)) {
                        prompt.setVisibility(View.GONE);
                }
           
//                cbSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//
//                        @Override
//                        public void onCheckedChanged(CompoundButton buttonView,
//                                                     boolean isChecked) {
//                                if (isChecked) {
//                                        rlDisable.setVisibility(View.GONE);
//                                        rlSensor.setVisibility(View.VISIBLE);
//
//                                }
//                                else {
//                                        rlDisable.setVisibility(View.VISIBLE);
//                                        rlSensor.setVisibility(View.GONE);
//                                }
//
//                        }
//                });

        }

        @Override
        public void onClick(View v) {
                Intent intent = new Intent(this, StarttheVoiceActivity.class);
                switch (v.getId()) {
                        case R.id.prompt:
                                prompt.setVisibility(View.GONE);
                                SharedPreferences sp = getSharedPreferences("sensor_prompt",
                                        Context.MODE_PRIVATE);
                                Editor editor = sp.edit();
                                editor.putString("isPlayed", "yes");
                                editor.apply();
                                break;
                        case R.id.btn_head_back:
                                finish();
                                return;
                        case R.id.ivHead:
                                //intent.putExtra("SensorBackActivity", "ivHead");
                                intent.putExtra("SensorBackActivity", IntentKey.SENSOR_HEAD);
                                // startActivity(intent);
                                break;
//                        case R.id.ivHeadBack:
//                                //  intent.putExtra("SensorBackActivity", "ivHeadBack");
//                                intent.putExtra("SensorBackActivity", IntentKey.SENSOR_HEAD_BACK);
//                                // startActivity(intent);
//                                break;
                        case R.id.ivLeftEar:
                                // intent.putExtra("SensorBackActivity", "ivLeftEar");
                                intent.putExtra("SensorBackActivity", IntentKey.SENSOR_LEFT_EAR);
                                //startActivity(intent);
                                break;
                        case R.id.ivRightEar:
                                // intent.putExtra("SensorBackActivity", "ivRightEar");
                                intent.putExtra("SensorBackActivity", IntentKey.SENSOR_RIGHT_EAR);
                                // startActivity(intent);
                                break;
//            case R.id.ivLeftHand:
//               // intent.putExtra("SensorBackActivity", "ivLeftHand");
//                intent.putExtra("SensorBackActivity", IntentKey.SENSOR_LEFT_HAND);
//               // startActivity(intent);
//                break;
//            case R.id.ivRightHand:
//              //  intent.putExtra("SensorBackActivity", "ivRightHand");
//                intent.putExtra("SensorBackActivity", IntentKey.SENSOR_RIGHT_HAND);
//               // startActivity(intent);
//                break;
                        case R.id.ivNeck:
                                //intent.putExtra("SensorBackActivity", "ivNeck");
                                intent.putExtra("SensorBackActivity", IntentKey.SENSOR_NECK);
                                // startActivity(intent);
                                break;
                        case R.id.ivBelly:
                                // intent.putExtra("SensorBackActivity", "ivBelly");
                                intent.putExtra("SensorBackActivity", IntentKey.SENSOR_BELLY);
                                // startActivity(intent);
                                break;
                        case R.id.ivButt:
                                // intent.putExtra("SensorBackActivity", "ivButt");
                                intent.putExtra("SensorBackActivity", IntentKey.SENSOR_BUTT);
                                // startActivity(intent);
                                break;
                }
                startActivity(intent);
        }

}
